package cn.hairui.blog.controller.manage;

import cn.hairui.blog.constant.PubConstant;
import cn.hairui.blog.model.User;
import cn.hairui.blog.service.impl.UserServiceImpl;
import cn.hairui.blog.util.MD5;
import com.alibaba.druid.support.json.JSONUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/8/4 14:48
 */
@Controller
@RequestMapping("/manage")
public class UserManageController {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(value = "/finduser", method = RequestMethod.POST)
    @ResponseBody
    public String find(User user, HttpServletRequest request) {
        Map map = new HashMap<Object, Object>();
        String username = user.getUsername();
        String password = MD5.getMD5ofStr(user.getPassword());
        System.out.println(username + " " + password);
        User domain = userService.findByUsernameAndPwd(username, password);
        if (domain != null) {
            map.put(PubConstant.flag, PubConstant.success);
        } else {
            map.put(PubConstant.flag, PubConstant.failed);
        }
        return JSONUtils.toJSONString(map);
    }

    @RequestMapping(value = "/page/user/userInfo")
    public String userInfo() {
        return "manage/page/user/userInfo";
    }

    @RequestMapping(value = "/page/user/changePwd")
    public String changePwd() {
        return "manage/page/user/changePwd";
    }
}
